<script>
    const queryData = () =>{
        return new Promise(resolve =>{
            let xhr = new XMLHttpRequest;
            xhr.open("GET","地址");
            xhr.onreadystatechange = () =>{
                let {readyState,status,responseText } = xhr;
                if(readyState === 4 && status ===200){
                    data = JSON.parse(responseText);
                    // 请求成功后 值为服务器获取结果
                    resolve(data);
                }
            }
            xhr.send();
        });
    };

queryData().then(value =>{
    console.log('请求成功',value);
    // ...  继续做某事
});


(async () =>{
 let value = await queryData();
 console.log("成功",value);
 //
})();
</script>